﻿using System;
using Imaginecup.stage;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using imaginecup.objectManager;
using Imaginecup.util.resourceMan;
using Imaginecup.gameState.malaria.component;
using Imaginecup.gameState.malaria.componentInit;
using Imaginecup.util;
using Imaginecup.loop;
using Imaginecup.sprite;
using Imaginecup.sprite.util;
using imaginecup.util;
using Imaginecup.util.input;
using Imaginecup.iterator;

namespace Imaginecup.gameState.malaria.loop
{
    public class DrawObjectMan:IDrawAble
    {
        private ObjectManager m_ObjMan;
        private ParticleMan m_ParticleMan;
        private TouchTrailLayer m_TouchTrailMan;
        private ISprite m_Sprite;
        private ISprite m_BackSprite;
        private bool m_Selected;

        private EntityInfo m_BackInfo;

        public DrawObjectMan(ObjectManager objMan )
        {
           // m_ObjectGrobalData = objGrobalData;
            m_ParticleMan = ParticleMan.GetParticleMan();
            m_ObjMan = objMan;
            m_TouchTrailMan = TouchTrailLayer.GetTouchTrailLayer();

            ChangeSourceSizeUtil sourceSizeUtil = new ChangeSourceSizeUtil();
            m_Sprite = sourceSizeUtil.GetChangeSourceSizeUtil("UI");

            NormalSprite backSprite = new NormalSprite();
            backSprite.SetTextureName("Back");

            m_BackSprite = backSprite;

            m_BackInfo = new EntityInfo(0, 0, 800, 480);
        }

        public void Release()
        {
            m_ObjMan = null;
            m_ParticleMan = null;
            m_BackSprite.Release();
            
        }

        public void SetData(Object data)
        {
            m_Selected = (bool)data;
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            ListIterator list = new ListIterator();
            list.Add(ComponentTypeID.CID_RENDER_FIELD_ITEM);
            list.Add(ComponentTypeID.CID_RENDER_MALARIA);
            list.Add(ComponentTypeID.CID_RENDER_CHILD);
            list.Add(ComponentTypeID.CID_RENDER_PROGRESSBAR);
            list.Add(ComponentTypeID.CID_RENDER_ITEMPANEL);
            list.Add(ComponentTypeID.CID_RENDER_TOP);

            m_BackSprite.Draw(spriteBatch, m_BackInfo);
            m_Sprite.Draw(spriteBatch, m_BackInfo);

            m_ObjMan.Draw(list, gameTime, spriteBatch);

          //  m_ObjMan.BroadCastMessage(msg, ComponentTypeID.CID_RENDER_FIELD_ITEM);
          //  m_ObjMan.BroadCastMessage(msg, ComponentTypeID.CID_RENDER_MALARIA);
          //  m_ObjMan.BroadCastMessage(msg , ComponentTypeID.CID_RENDER_CHILD);
          //  m_ObjMan.BroadCastMessage(msg, ComponentTypeID.CID_RENDER_PROGRESSBAR);
          ////  m_ObjMan.BroadCastMessage(msg, ComponentTypeID.CID_RENDER_FACTORYUI);
          //  m_ObjMan.BroadCastMessage(msg, ComponentTypeID.CID_RENDER_ITEMPANEL);
          //  m_ObjMan.BroadCastMessage(msg, ComponentTypeID.CID_RENDER_TOP);


            m_TouchTrailMan.Draw();
        }

    }
}


